package hu.myandroidlife.activity;

import hu.myandroidlife.R;
import hu.myandroidlife.R.id;
import hu.myandroidlife.R.layout;
import hu.myandroidlife.base.BaseActivity;
import hu.myandroidlife.myview.RoundProgressBar;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ShanXingProgressBarActivity extends BaseActivity {

	private RoundProgressBar roundProgressBar;
	private Button btnStart;
	private Button btnReset;

	private int progress = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	protected int getLayoutId() {
		return R.layout.activity_shan_xing_progress_bar;
	}

	@Override
	public void initView() {
		roundProgressBar = $findViewById(R.id.roundProgressBar);
		btnStart = $findViewById(R.id.btnStart);
		btnReset = $findViewById(R.id.btnReset);
	}

	@Override
	public void initListener() {
		btnStart.setOnClickListener(this);
		btnReset.setOnClickListener(this);
	}

	@Override
	public void widgetClick(View v) {
		switch (v.getId()) {
		case R.id.btnStart:
			new Thread(new Runnable() {

				@Override
				public void run() {
					while (progress <= 100) {
						progress += 3;

						$log(progress + "");

						roundProgressBar.setProgress(progress);

						try {
							Thread.sleep(100);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
					runOnUiThread(new Runnable() {
						public void run() {
							roundProgressBar.setVisibility(View.INVISIBLE);
						}
					});

				}
			}).start();
			break;
		case R.id.btnReset:
			roundProgressBar.setVisibility(View.VISIBLE);
			roundProgressBar.setProgress(0);
			progress = 0;
			break;
		default:
			break;
		}
	}
}
